package com.spring.lifecycle.bean;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Title：@Value 赋值
 *
 *     @Value("张三")//直接赋值
 *     private String name;
 *     @Value("#{20-2}")//spel表达式
 *     private Integer age;
 *     @Value("${boy.home}")//从配置文件读取值
 *          // @PropertySource(value = {"classpath:/application.properties"}) @PropertySource读取外部配置文件
 */
@Component
public class Boy implements InitializingBean, DisposableBean {

    @Value("张三")
    private String name;
    @Value("#{20-2}")
    private Integer age;
    @Value("${boy.home}")
    private String home;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getHome() {
        return home;
    }

    public void setHome(String home) {
        this.home = home;
    }

    public Boy(String name, Integer age, String home) {
        this.name = name;
        this.age = age;
        this.home = home;
    }

    @Override
    public String toString() {
        return "Boy{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", home='" + home + '\'' +
                '}';
    }

    public Boy() {
        System.out.println("boy constructor...");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("实现InitializingBean接口进行销毁。。。");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("实现DisposableBean接口进行初始化。。。");
    }
}
